<?php

namespace addons\fastflow;

use app\common\library\Menu;
use think\Addons;

/**
 * 插件
 */
class Fastflow extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name' => 'fastflow',
                'title' => '工作流系统',
                'icon' => 'fa fa-list-alt',
                'sublist' =>[
                                [
                                    "name" => 'fastflow/bill',
                                    "title" => "单据列表",
                                    "icon" => 'fa fa-list-alt',
                                    "weigh" => -1,
                                    "sublist" => [
                                        [
                                            "name" => 'fastflow/bill/fastflow_demo_leave',
                                            "title" => "请假审批(演示)",
                                            "icon" => 'fa fa-user-circle-o',
                                            "weigh" => -1,
                                            "sublist" => [
                                                ["name" => 'fastflow/bill/fastflow_demo_leave/index', "title" => '查看'],
                                                ["name" => 'fastflow/bill/fastflow_demo_leave/add', "title" => '添加'],
                                                ["name" => 'fastflow/bill/fastflow_demo_leave/edit', "title" => '编辑'],
                                                ["name" => 'fastflow/bill/fastflow_demo_leave/del', "title" => '删除'],
                                                ["name" => 'fastflow/bill/fastflow_demo_leave/multi', "title" => '批量更新'],
                                            ]
                                        ]
                                    ]
                                ],
                                [
                                    "name" => 'fastflow/flow',
                                    "title" => "系统管理",
                                    "icon" => 'fa fa-list',
                                    "weigh" => -2,
                                    "sublist" => [
										[
                                            "name" => 'fastflow/flow/bill',
                                            "title" => "单据管理",
                                            "icon" => 'fa fa-clipboard',
                                            "weigh" => -1,
                                            "sublist" => [
                                                ["name" => 'fastflow/flow/bill/edit', "title" => '编辑'],
                                                ["name" => 'fastflow/flow/bill/add', "title" => '新增单据'],
												["name" => 'fastflow/flow/bill/fromtable', "title" => '从数据表创建单据'],
                                                ["name" => 'fastflow/flow/bill/del', "title" => '删除单据'],
                                                ["name" => 'fastflow/flow/bill/index', "title" => '查看'],
                                                ["name" => 'fastflow/flow/bill/multi', "title" => '批量更新'],
                                                ["name" => 'fastflow/flow/bill/auth', "title" => '权限配置'],
                                            ]
                                        ],
                                        [
                                            "name" => 'fastflow/flow/flow',
                                            "title" => "流程管理",
                                            "icon" => 'fa fa-list-alt',
                                            "weigh" => -2,
                                            "sublist" => [
                                                ["name" => 'fastflow/flow/flow/index', "title" => '查看'],
                                                ["name" => 'fastflow/flow/flow/add', "title" => '添加'],
                                                ["name" => 'fastflow/flow/flow/edit', "title" => '编辑'],
                                                ["name" => 'fastflow/flow/flow/del', "title" => '删除'],
                                                ["name" => 'fastflow/flow/flow/multi', "title" => '批量更新'],
                                                ["name" => 'fastflow/flow/flow/designer', "title" => '流程设计'],
                                                ["name" => 'fastflow/flow/flow/detail', "title" => '详情'],
												["name" => 'fastflow/flow/flow/exportWord', "title" => '保存为Word'],
												["name" => 'fastflow/flow/flow/auth', "title" => '权限配置'],
                                                ["name" => 'fastflow/flow/flow/savegraph', "title" => '保存流程图'],
                                                ["name" => 'fastflow/flow/flow/import', "title" => '导入'],
                                            ]
                                        ],
                                        [
                                            "name" => 'fastflow/flow/process',
                                            "title" => "流程监控",
                                            "icon" => 'fa fa-tv',
                                            "weigh" => -3,
                                            "sublist" => [
                                                ["name" => 'fastflow/flow/process/edit', "title" => '编辑'],
                                                ["name" => 'fastflow/flow/process/add', "title" => '添加'],
                                                ["name" => 'fastflow/flow/process/del', "title" => '删除'],
                                                ["name" => 'fastflow/flow/process/termination', "title" => '强制终止'],
                                                ["name" => 'fastflow/flow/process/index', "title" => '查看'],
                                                ["name" => 'fastflow/flow/process/multi', "title" => '批量更新'],
                                            ]
                                        ],
                                        [
                                            "name" => 'fastflow/flow/agency',
                                            "title" => "委托代理",
                                            "icon" => 'fa fa-handshake-o',
                                            "weigh" => -4,
                                            "sublist" => [
                                                ["name" => 'fastflow/flow/agency/edit', "title" => '编辑'],
                                                ["name" => 'fastflow/flow/agency/add', "title" => '添加'],
                                                ["name" => 'fastflow/flow/agency/del', "title" => '删除'],
                                                ["name" => 'fastflow/flow/agency/index', "title" => '查看'],
                                                ["name" => 'fastflow/flow/agency/multi', "title" => '批量更新'],
                                            ]
                                        ],
                                        [
                                            "name" => 'fastflow/flow/message',
                                            "title" => "消息配置",
                                            "icon" => 'fa fa-envelope-o',
                                            "weigh" => -5,
                                            "sublist" => [
                                                ["name" => 'fastflow/flow/message/edit', "title" => '编辑'],
                                                ["name" => 'fastflow/flow/message/add', "title" => '添加'],
                                                ["name" => 'fastflow/flow/message/del', "title" => '删除'],
                                                ["name" => 'fastflow/flow/message/index', "title" => '查看'],
                                                ["name" => 'fastflow/flow/message/multi', "title" => '批量更新'],
                                                ["name" => 'fastflow/flow/message/import', "title" => '导入'],
												["name" => 'fastflow/flow/message/test', "title" => '消息测试'],
                                            ]
                                        ],
                                    ]
                                ],
								[
                                    "name" => 'fastflow/carbon',
                                    "title" => "我的抄送",
                                    "icon" => 'fa fa-paper-plane',
                                    "weigh" => -3,
                                    "sublist" => [
                                        ["name" => 'fastflow/carbon/index', "title" => '查看'],
										["name" => 'fastflow/carbon/del', "title" => '删除'],
										["name" => 'fastflow/carbon/multi', "title" => '批量更新'],
										["name" => 'fastflow/carbon/detail', "title" => '详情'],
                                        ["name" => 'fastflow/carbon/exportWord', "title" => '保存为Word'],
                                    ]
                                ],
                            ],

            ],
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("fastflow");
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable("fastflow");
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable("fastflow");
        return true;
    }

    /**
     * 应用初始化
     */
    public function appInit()
    {
        \think\Loader::addNamespace('fastflow', ADDON_PATH . 'fastflow' . DS . 'library' . DS . 'fastflow' . DS);
        if (request()->isCli()) {
            \think\Console::addDefaultCommands([
                'addons\fastflow\command\Crud',
                'addons\fastflow\command\Menu',
            ]);
        }
    }

}
